/*
 * Copyright 2020-2030 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
*/

package com.gitee.minimalismstyle.fresh.flowable.api.feign

import org.springframework.web.bind.annotation.*
import com.gitee.minimalismstyle.fresh.common.core.domain.R
import com.gitee.minimalismstyle.fresh.flowable.api.annotation.FlowableClient
import com.gitee.minimalismstyle.fresh.flowable.api.config.FlowableFeignConfig
import com.gitee.minimalismstyle.fresh.flowable.api.feign.model.DataResponse
import com.gitee.minimalismstyle.fresh.flowable.api.feign.model.HistoryJobResponse
import com.gitee.minimalismstyle.fresh.flowable.api.feign.model.JobResponse
import com.gitee.minimalismstyle.fresh.flowable.api.feign.model.RestActionRequest

/**
 * Jobs
 * @author maoxiaodong
 */
@FlowableClient(configuration = [FlowableFeignConfig::class])
interface JobsApi {


    /**
     * List deadletter jobs
     */
    @GetMapping("/management/deadletter-jobs")
    fun listDeadLetterJobs(
        @RequestParam(name = "id", required = false) id: String?,
        @RequestParam(name = "processInstanceId", required = false) processInstanceId: String?,
        @RequestParam(name = "executionId", required = false) executionId: String?,
        @RequestParam(name = "processDefinitionId", required = false) processDefinitionId: String?,
        @RequestParam(name = "elementId", required = false) elementId: String?,
        @RequestParam(name = "elementName", required = false) elementName: String?,
        @RequestParam(name = "executable", required = false) executable: Boolean?,
        @RequestParam(name = "timersOnly", required = false) timersOnly: Boolean?,
        @RequestParam(name = "messagesOnly", required = false) messagesOnly: Boolean?,
        @RequestParam(name = "withException", required = false) withException: Boolean?,
        @RequestParam(name = "dueBefore", required = false) dueBefore: String?,
        @RequestParam(name = "dueAfter", required = false) dueAfter: String?,
        @RequestParam(name = "exceptionMessage", required = false) exceptionMessage: String?,
        @RequestParam(name = "tenantId", required = false) tenantId: String?,
        @RequestParam(name = "tenantIdLike", required = false) tenantIdLike: String?,
        @RequestParam(name = "withoutTenantId", required = false) withoutTenantId: Boolean?,
        @RequestParam(name = "locked", required = false) locked: Boolean?,
        @RequestParam(name = "unlocked", required = false) unlocked: Boolean?,
        @RequestParam(name = "withoutScopeType", required = false) withoutScopeType: Boolean?,
        @RequestParam(name = "sort", required = false) sort: String?
    ): R<DataResponse<JobResponse>>

    /**
     * Get a single deadletter job
     */
    @GetMapping("/management/deadletter-jobs/{jobId}")
    fun getDeadletterJob(
        @PathVariable("jobId") jobId: String
    ): R<JobResponse>

    /**
     * Move a single deadletter job. Accepts 'move' and 'moveToHistoryJob' as action.
     */
    @PostMapping("/management/deadletter-jobs/{jobId}")
    fun executeDeadLetterJobAction(
        @PathVariable("jobId") jobId: String,
        @RequestBody(required = false) body: RestActionRequest?
    ): R<Any>

    /**
     * Delete a deadletter job
     */
    @DeleteMapping("/management/deadletter-jobs/{jobId}")
    fun deleteDeadLetterJob(
        @PathVariable("jobId") jobId: String
    ): R<Any>

    /**
     * Get the exception stacktrace for a deadletter job
     */
    @GetMapping("/management/deadletter-jobs/{jobId}/exception-stacktrace")
    fun getDeadLetterJobStacktrace(
        @PathVariable("jobId") jobId: String
    ): R<Any>

    /**
     * List history jobs
     */
    @GetMapping("/management/history-jobs")
    fun listDeadLetterJobs(
        @RequestParam(name = "id", required = false) id: String?,
        @RequestParam(name = "withException", required = false) withException: Boolean?,
        @RequestParam(name = "exceptionMessage", required = false) exceptionMessage: String?,
        @RequestParam(name = "scopeType", required = false) scopeType: String?,
        @RequestParam(name = "tenantId", required = false) tenantId: String?,
        @RequestParam(name = "tenantIdLike", required = false) tenantIdLike: String?,
        @RequestParam(name = "withoutTenantId", required = false) withoutTenantId: Boolean?,
        @RequestParam(name = "lockOwner", required = false) lockOwner: String?,
        @RequestParam(name = "locked", required = false) locked: Boolean?,
        @RequestParam(name = "unlocked", required = false) unlocked: Boolean?,
        @RequestParam(name = "sort", required = false) sort: String?
    ): R<DataResponse<HistoryJobResponse>>

    /**
     * Get a single history job job
     */
    @GetMapping("/management/history-jobs/{jobId}")
    fun getHistoryJob(
        @PathVariable("jobId") jobId: String
    ): R<HistoryJobResponse>

    /**
     * Execute a history job
     */
    @PostMapping("/management/history-jobs/{jobId}")
    fun executeHistoryJob(
        @PathVariable("jobId") jobId: String,
        @RequestBody(required = false) body: RestActionRequest?
    ): R<Any>

    /**
     * Delete a history job
     */
    @DeleteMapping("/management/history-jobs/{jobId}")
    fun deleteHistoryJob(
        @PathVariable("jobId") jobId: String
    ): R<Any>

    /**
     * List jobs
     */
    @GetMapping("/management/jobs")
    fun listJobs(
        @RequestParam(name = "id", required = false) id: String?,
        @RequestParam(name = "processInstanceId", required = false) processInstanceId: String?,
        @RequestParam(name = "executionId", required = false) executionId: String?,
        @RequestParam(name = "processDefinitionId", required = false) processDefinitionId: String?,
        @RequestParam(name = "elementId", required = false) elementId: String?,
        @RequestParam(name = "elementName", required = false) elementName: String?,
        @RequestParam(name = "timersOnly", required = false) timersOnly: Boolean?,
        @RequestParam(name = "messagesOnly", required = false) messagesOnly: Boolean?,
        @RequestParam(name = "withException", required = false) withException: Boolean?,
        @RequestParam(name = "dueBefore", required = false) dueBefore: String?,
        @RequestParam(name = "dueAfter", required = false) dueAfter: String?,
        @RequestParam(name = "exceptionMessage", required = false) exceptionMessage: String?,
        @RequestParam(name = "tenantId", required = false) tenantId: String?,
        @RequestParam(name = "tenantIdLike", required = false) tenantIdLike: String?,
        @RequestParam(name = "withoutTenantId", required = false) withoutTenantId: Boolean?,
        @RequestParam(name = "locked", required = false) locked: Boolean?,
        @RequestParam(name = "unlocked", required = false) unlocked: Boolean?,
        @RequestParam(name = "withoutScopeType", required = false) withoutScopeType: Boolean?,
        @RequestParam(name = "sort", required = false) sort: String?
    ): R<DataResponse<JobResponse>>

    /**
     * Get a single job
     */
    @GetMapping("/management/jobs/{jobId}")
    fun getJob(
        @PathVariable("jobId") jobId: String
    ): R<JobResponse>

    /**
     * Execute a single job
     */
    @PostMapping("/management/jobs/{jobId}")
    fun executeJobAction(
        @PathVariable("jobId") jobId: String,
        @RequestBody(required = false) body: RestActionRequest?
    ): R<Any>

    /**
     * Delete a job
     */
    @DeleteMapping("/management/jobs/{jobId}")
    fun deleteJob(
        @PathVariable("jobId") jobId: String
    ): R<Any>

    /**
     * Get the exception stacktrace for a job
     */
    @GetMapping("/management/jobs/{jobId}/exception-stacktrace")
    fun getJobStacktrace(
        @PathVariable("jobId") jobId: String
    ): R<Any>

    /**
     * List suspended jobs
     */
    @GetMapping("/management/suspended-jobs")
    fun listSuspendedJobs(
        @RequestParam(name = "id", required = false) id: String?,
        @RequestParam(name = "processInstanceId", required = false) processInstanceId: String?,
        @RequestParam(name = "executionId", required = false) executionId: String?,
        @RequestParam(name = "processDefinitionId", required = false) processDefinitionId: String?,
        @RequestParam(name = "elementId", required = false) elementId: String?,
        @RequestParam(name = "elementName", required = false) elementName: String?,
        @RequestParam(name = "executable", required = false) executable: Boolean?,
        @RequestParam(name = "timersOnly", required = false) timersOnly: Boolean?,
        @RequestParam(name = "messagesOnly", required = false) messagesOnly: Boolean?,
        @RequestParam(name = "withException", required = false) withException: Boolean?,
        @RequestParam(name = "dueBefore", required = false) dueBefore: String?,
        @RequestParam(name = "dueAfter", required = false) dueAfter: String?,
        @RequestParam(name = "exceptionMessage", required = false) exceptionMessage: String?,
        @RequestParam(name = "tenantId", required = false) tenantId: String?,
        @RequestParam(name = "tenantIdLike", required = false) tenantIdLike: String?,
        @RequestParam(name = "withoutTenantId", required = false) withoutTenantId: Boolean?,
        @RequestParam(name = "locked", required = false) locked: Boolean?,
        @RequestParam(name = "unlocked", required = false) unlocked: Boolean?,
        @RequestParam(name = "withoutScopeType", required = false) withoutScopeType: Boolean?,
        @RequestParam(name = "sort", required = false) sort: String?
    ): R<DataResponse<JobResponse>>

    /**
     * Get a single suspended job
     */
    @GetMapping("/management/suspended-jobs/{jobId}")
    fun getSuspendedJob(
        @PathVariable("jobId") jobId: String
    ): R<JobResponse>

    /**
     * Delete a suspended job
     */
    @DeleteMapping("/management/suspended-jobs/{jobId}")
    fun deleteSuspendedJob(
        @PathVariable("jobId") jobId: String
    ): R<Any>

    /**
     * Get the exception stacktrace for a suspended job
     */
    @GetMapping("/management/suspended-jobs/{jobId}/exception-stacktrace")
    fun getSuspendedJobStacktrace(
        @PathVariable("jobId") jobId: String
    ): R<Any>

    /**
     * List timer jobs
     */
    @GetMapping("/management/timer-jobs")
    fun listTimerJobs(
        @RequestParam(name = "id", required = false) id: String?,
        @RequestParam(name = "processInstanceId", required = false) processInstanceId: String?,
        @RequestParam(name = "executionId", required = false) executionId: String?,
        @RequestParam(name = "processDefinitionId", required = false) processDefinitionId: String?,
        @RequestParam(name = "elementId", required = false) elementId: String?,
        @RequestParam(name = "elementName", required = false) elementName: String?,
        @RequestParam(name = "executable", required = false) executable: Boolean?,
        @RequestParam(name = "timersOnly", required = false) timersOnly: Boolean?,
        @RequestParam(name = "messagesOnly", required = false) messagesOnly: Boolean?,
        @RequestParam(name = "withException", required = false) withException: Boolean?,
        @RequestParam(name = "dueBefore", required = false) dueBefore: String?,
        @RequestParam(name = "dueAfter", required = false) dueAfter: String?,
        @RequestParam(name = "exceptionMessage", required = false) exceptionMessage: String?,
        @RequestParam(name = "tenantId", required = false) tenantId: String?,
        @RequestParam(name = "tenantIdLike", required = false) tenantIdLike: String?,
        @RequestParam(name = "withoutTenantId", required = false) withoutTenantId: Boolean?,
        @RequestParam(name = "locked", required = false) locked: Boolean?,
        @RequestParam(name = "unlocked", required = false) unlocked: Boolean?,
        @RequestParam(name = "withoutScopeType", required = false) withoutScopeType: Boolean?,
        @RequestParam(name = "sort", required = false) sort: String?
    ): R<DataResponse<JobResponse>>

    /**
     * Get a single timer job
     */
    @GetMapping("/management/timer-jobs/{jobId}")
    fun getTimerJob(
        @PathVariable("jobId") jobId: String
    ): R<JobResponse>

    /**
     * Move a single timer job
     */
    @PostMapping("/management/timer-jobs/{jobId}")
    fun executeTimerJobAction(
        @PathVariable("jobId") jobId: String,
        @RequestBody(required = false) body: RestActionRequest?
    ): R<Any>

    /**
     * Delete a timer job
     */
    @DeleteMapping("/management/timer-jobs/{jobId}")
    fun deleteTimerJob(
        @PathVariable("jobId") jobId: String
    ): R<Any>

    /**
     * Get the exception stacktrace for a timer job
     */
    @GetMapping("/management/timer-jobs/{jobId}/exception-stacktrace")
    fun getTimerJobStacktrace(
        @PathVariable("jobId") jobId: String
    ): R<Any>
}